<?php

class SimpleContactForm extends sfForm{

   public function configure()
   {

     sfProjectConfiguration::getActive()->loadHelpers(array('I18N'));

     $this->setNameFormat();

     $this->widgetSchema['nimi'] = new sfWidgetFormInput();
     $this->widgetSchema['email'] = new sfWidgetFormInput();
     $this->widgetSchema['lisainfo'] = new sfWidgetFormTextarea();
	 $this->widgetSchema['captcha'] = new sfWidgetFormInput();

	 
     $this->setValidators( array(
        'nimi' => new sfValidatorString(array('required' => false,'min_length' => 0, 'max_length' => 100)),
        'email' => new sfValidatorEmail(array('required' => true,'max_length' => 100), array('invalid' => __('wrong email'), 'required' => __('email is required'))),
        'lisainfo' => new sfValidatorString(array('required' => false,'min_length' => 0, 'max_length' => 700)),
     	'captcha' => new sfCaptchaGDValidator(array('length' => 4), array('invalid' => 'wrong captcha code')),
      ));

	 
	 $this->setDefaults(array(
		 'nimi' => 'Nimi',
		 'email' => 'Email',
		 'lisainfo' => 'Teade',
		 'captcha' => 'Kood'
	 ));

   }


   public function setNameFormat(){
        $this->widgetSchema->setNameFormat('contact[%s]');
   }

   public function validateForm(sfWebRequest $request){
       $this->bind($request->getParameter($this->getName()), array());

       if($this->isValid()){
           return true;
       }else{
           return false;
       }

   }

   public function getErrors(){
   $result = array();

    foreach($this->getErrorSchema() as $index => $val){
        $result[$index] = $val->__toString();
    }
    return $result;
    
   }


}